/**************************************************************************************
 *  Copyright (c)  2010  Leszek Karcz, Changmin Bae.
 *  Permission is granted to copy, distribute and/or modify this document
 *  under the terms of the GNU Free Documentation License, Version 1.3
 *  or any later version published by the Free Software Foundation;
 *  with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 *  A copy of the license is included in the section entitled "GNU
 *  Free Documentation License". 
 **************************************************************************************/
package data.tileables;
import data.Map;
import data.Player;
import data.Tile;
import data.missions.PowerDown;
import data.missions.PowerUp;

/**************************************************************************************
 * Author(s): Leszek Karcz, Changmin Bae
 * PowerPlant building, for creating power
 **************************************************************************************/
public class PowerPlant extends HarvestStructure
{
	public static final int [] PRICE = { 10, 30, 20 };
	
	/**************************************************************************************
	 * Author(s): Leszek Karcz, Changmin Bae
	 * PowerPlant constructor
	 **************************************************************************************/
	public PowerPlant(int ID, int supertypeID, Player player, int workers)
	{
		super(ID, supertypeID, player, workers);
		this.setType("Power Plant");
		this.setImage("struct_plant");
		this.setIcon("struct_plant");
		this.setStats(6, 3.34, 100, 50, 0, 10, 1);
		this.setUpkeep(new int[]{0,2,1});
		this.setNumberOfCommands(4);		
	}
	
	

	public void die()
	{ 
		super.die();
		player.removePlant(this);
	}
	
	/**************************************************************************************
	 * Author(s): Changmin Bae
	 * Assigns workers
	 **************************************************************************************/
	public boolean assignWorkers(int workers, Map map, int x, int y, int type)
	{
		if(!(map.checkRadius(this.getX(), getY(), x, y, this.getVisionRadius())))
			return false;		
		Tile temp = map.getTile(x, y);		
		if(temp.getResources() == null)
			return false;
		workers = this.decUnassignedWorkers(workers);		
		if(workers == 0)
		{
			incUnassignedWorkers(harvest.unassignAllWorkers());
		}
		else
		{			
			harvest.addResource(temp.getResources(), this);
			harvest.assignWorkers(workers, temp.getResources());
		}		
		return true;		
	}
}
